package com.tuanzhang.mall.goods.domain.aggregate;

import com.tuanzhang.mall.goods.domain.valueobj.Category;
import com.tuanzhang.mall.goods.domain.valueobj.MoneyRange;
import com.tuanzhang.mall.goods.domain.valueobj.Sku;
import com.tuanzhang.mall.goods.domain.valueobj.SpuCode;
import com.tuanzhang.mall.seller.domain.valueobj.PhoneNumber;
import com.tuanzhang.mall.seller.types.exception.ApiException;
import lombok.Getter;

import java.util.List;

/**
 * @author wangyl
 */
@Getter
public class Spu {

    private SpuCode spuCode;

    private PhoneNumber sellerPhoneNumber;

    private String spuName;

    private List<String> images;

    private Category category;


    private MoneyRange priceRange;

    private List<Sku> skus;

    private boolean recommendFlag;


    private Spu() {
    }

    private Spu(SpuCode spuCode, PhoneNumber sellerPhoneNumber, String spuName, List<String> images, Category category, MoneyRange priceRange, List<Sku> skus, boolean recommendFlag) {
        this.spuCode = spuCode;
        this.sellerPhoneNumber = sellerPhoneNumber;
        this.spuName = spuName;
        this.images = images;
        this.category = category;
        this.priceRange = priceRange;
        this.skus = skus;
    }

    public static Spu createSpu(SpuCode spuCode, PhoneNumber sellerPhoneNumber, String spuName, List<String> images, Category category, MoneyRange priceRange, List<Sku> skus, boolean recommendFlag) {
        return new Spu(spuCode, sellerPhoneNumber, spuName, images, category, priceRange, skus, recommendFlag);
    }

    public void recommend() {
        if (this.recommendFlag) {
            throw new ApiException("商品已推荐");
        }
        this.recommendFlag = true;
    }
}